package com.lg.order.producer.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.Exchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author by Mr. Li 2020/12/11 9:50
 */
@Configuration
@Slf4j
public class MyMQConfig {

    /**
     * 交换机名称
     */
    public static final String DISTRIBUTED_TRANSACTION_EVENT_EXCHANGE = "distributed-transaction-event-exchange";

    /**
     * 路由键
     */
    public static final String DISTRIBUTED_TRANSACTION_KEY = "distributed.transaction.key";

    /**
     * 队列名称
     */
    public static final String DISTRIBUTED_TRANSACTION_QUEUE = "distributed.transaction.queue";

    /**
     * 队列
     *
     * @return
     */
    @Bean
    public Queue distributedTransactionQueue() {
        return new Queue(DISTRIBUTED_TRANSACTION_QUEUE, true, false, false);
    }

    /**
     * 交换机
     *
     * @return
     */
    @Bean
    public Exchange distributedTransactionEventExchange() {
        return new TopicExchange(DISTRIBUTED_TRANSACTION_EVENT_EXCHANGE,
                true, false);
    }

    /**
     * 绑定路由键
     *
     * @return
     */
    @Bean
    public Binding distributedTransactionKeyBinding() {
        return new Binding(DISTRIBUTED_TRANSACTION_QUEUE,
                Binding.DestinationType.QUEUE,
                DISTRIBUTED_TRANSACTION_EVENT_EXCHANGE,
                DISTRIBUTED_TRANSACTION_KEY, null);
    }
}
